package com.usian.controller;


import com.usian.pojo.Users;
import com.usian.service.UserService;
import org.apache.ibatis.annotations.Param;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@Controller
public class UserController {
@Autowired
private UserService userService;

private final static Logger logger= LoggerFactory.getLogger(UserController.class);
    @RequestMapping("/show")
    public String show(Model model) {
        logger.info("成功 ");
   List<Users>list= userService.findAll();
   model.addAttribute("list",list);

    return "index";
    }
    @RequestMapping("goadd")
    public String goadd(){
        return "add";
    }


    @RequestMapping("/add")
    public String add(Users user){
        userService.add(user);
        return "redirect:/show";
    }
    @RequestMapping("/update")
    public String update(Users user){
        userService.update(user);
        return "redirect:/show";
    }
    @RequestMapping("findByid")
    private String findbyid(Model model,Integer id){
       Users users= userService.findbyid(id);
        model.addAttribute("list",users);
       return "update";
    }

    @RequestMapping("delete")
    private String delete(@Param("id") Integer id){
        userService.delete(id);
   return "redirect:/show";
    }


}